﻿// See https://aka.ms/new-console-template for more information
using System.Diagnostics;

Stopwatch stopwatch = Stopwatch.StartNew();
stopwatch.Start();
Console.WriteLine("Hello, World!");
int result = 0;
//for (int i = 1; i <= 10; i++)
//{
//    result += await TestMethod();
//}

List<Task<int>> task = new();
for (int i = 1; i <= 10; i++)
{
    task.Add(Task.Run(TestMethod));
}
await Task.WhenAll(task);
task.ForEach(async x =>
{
    result += await x;
});
stopwatch.Stop();

Console.WriteLine(result+$"  消耗时间{stopwatch.Elapsed}");

async Task<int> TestMethod()
{
    await Task.Delay(1000);
    return 1;
}